<?php
/*
 * @author eBIZ Team <dev@jungo.com.cn>
 * @copyright  Copyright (c) , ShenZhen JunGO Technology Co., Ltd. All rights reserved.
 * @license  Commercial authorization, unauthorized use and modification are prohibited
 * @url www.jungo.com.cn
 */

namespace ckeeper\utils;


use Swoole\Coroutine\System;

class UuidGenerator
{

    /**
     * @return string
     */
    public function generator()
    {
        // TODO:ToBeOptimized 优化方式、通过 Redis 获取 clock sequence，目前是使用uniqid进行的设置
        $microtime = microtime();
        $time1 = substr($microtime, -10);
        $time2 = substr($microtime, 2, 8);
        $time = $time1 . $time2;
        $code = dechex($time);
        $macAddress = MacAddress::get(PHP_OS);
        $uniqid = uniqid();
        $uuidArray = [
            substr($code, -8),
            substr($code, -12, 4),
            substr($uniqid, 0, 4),
            substr($uniqid, -4),
            str_replace(':', '', $macAddress),
        ];
        return implode('-', $uuidArray);
    }

}
